# Usage: python m.py

# 1. data <- Get-Data() [Get-Data1,...,Get-Data10]
# 2. data <- Mangling(data)
# 3. prompt <- Prompt-Making(data)
# 4. o <- LLM(prompt)
# 5. print_it(o)

# 6. r <- parse(o)
# 7. save(r) [r1,...,r10]

{
    'f1.m': {
        'hash1' : ['path1', 'path2'],
        'hash2' : ['path1', 'path2']
    }
}

# M1:
from pathlib import Path
import json
p = Path('~/aixcoder1/lierlu/count_results_without_comment.json')
o = json.
# 1.

def f1(s = 'hi.m', h = 'fb2b'):
    # to do
    s = ...

    # 5. call llm
    o = llm(s)
    # 6. print answer
    print(o)

    # 7. parse o and save (to-do)
    o1 = api_x(o)
    return o1

def f2(s = 'hi.m', h = 'fb2b', o1 = None):
    # 1. read full path hi.m
    p = o[s][h][0]
    # 2. invoke API
    p1, p2 = api_1(p)             # ('/path/hi.h','/path/hi.c')

    # 3. mangle (replace some compents...)
    p, p1, p2 = mangle(p), mangle(p1), mangle(p2)
    s, s1, s2 = map([p,p1,p2], read)

    # 3.1 (c-path
    s1 = api_modify_header(s1)  # f7
    # 3.2
    has_t :bool  = check_t(p2,s2)    # f6

    # 4. call the make-prompt api
    p0,o0,m0 = '', '', ''            # previous prompt , previous llm output, previous judge result
    while True:
        p0 = api_make_prompt(p,p1,s, s1,
                            p0,o0,m0
                            )  # 'ml_src_path', 'h_src_path'
        # 5. call llm
        o0 = api_llm(s)
        # 6. print answer
        print(o0)

        # 7. parse the last code block
        r1:str = get_last_code_block(o0)  # <block of c code>
        # 7.1 (path , generated) c -> better c

        # 8.
        r2:str = api_code_mangling(r1, has_t) # <processed block of c code>
        ok, m0 = api_judge(r2) # bool, judgement message
        if ok:
            print('✅️')
            break
        print('⚙️ re-trying')

